<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Categories Admin</title>
</head>
<body>

	<c:set var="message" value="${param.message}"></c:set>
	<c:set var="error" value="${param.error}"></c:set>
	<c:set var="success" value="${param.success}"></c:set>
	<c:set var="categories" value="${applicationScope.categories}"/>

	<c:if test="${user.userType ne 'Professor'}" >
		<c:redirect url="LoginServlet"></c:redirect>
	</c:if>

	<div id="header"><%@ include file="Header.jsp"%></div>
	<div id="content">
	<div id="navbar"><%@ include file="NavigationBar.jsp"%></div>
	
	<div id="main">
	
		<div class="box">
			<div class="box-header well">
				<h2><i class="icon-edit"></i> Add Category</h2>
				<div class="box-icon">
					<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
				</div>
			</div>
			
			<div class="box-content">
				<form class="form-horizontal" action="AddCategoryServlet" method="post">
					<fieldset>
						<label class="control-label">Category Information:</label>
						<div class="control-group">
							<br><br>
							<label class="control-label" for="focusedInput">*Category Name</label>
							<div class="controls">
								<input name="category_name" class="input-xlarge focused" type="text">
							</div>
						</div>
						
						<div class="form-actions">
							<button type="submit" class="btn btn-primary" name="createCategory">Create Category</button>
							<button class="btn" type="reset">Reset</button>
						</div>
					</fieldset>	  
				</form>   
			</div>
		</div>
			
			<div class="box">
				<div class="box-header well">
					<h2><i class="icon-tags"></i> View Categories</h2>
					<div class="box-icon">
						<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
					</div>
				</div>
				<div class="box-content">
					<table class="table table-striped table-bordered bootstrap-datatable datatable">
						<thead>
							<tr>
								<th>Category Name</th>
							</tr>
						</thead>   
						<tbody>
							<c:forEach var="category" items="${categories }">
								<tr><td>${category }</td></tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
	
	
	<c:choose>
	<c:when test="${not empty message}">
	<script>$(document).ready(function() {$.noty({ text: '${message}', type: 'information', layout: 'top'});});</script>
	</c:when>
	<c:when test="${not empty error}">
	<script>$(document).ready(function() {$.noty({ text: '${error}',type: 'error',layout: 'top'});});</script>
	</c:when>
	<c:when test="${not empty success}">
	<script>$(document).ready(function() {$.noty({text: '${success}',type: 'success',layout: 'top'});});</script>
	</c:when>
	</c:choose>
	
	</div>
	</div>
	
	<script>
		$(document).ready(function() {
			
			$("button[name='createCategory']").click(function() {
				$(".help-inline").remove();
				
				if($("input[name='category_name']").val().length == 0) {
					$("input[name='category_name']").after("<span class='help-inline'>Empty Field!</span>").parent().parent().addClass("error");
					return false;
				}
			});
		});
	</script>

</body>
</html>